<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"yoursite.com","root":"/","scheme":"Muse","version":"7.7.1","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="find指令在目录结构中搜索文件，并执行指定的操作。 1.命令格式find 路径 选项[-print -exec -ok..] 2.命令功能用于文件树中查找文件，并做出相应的处理 3.命令参数路径（pathname) : find命令查找的目录路径，用 . 表示当前目录，用 &#x2F; 表示系统目录  find . text.c  用此指令时会出现所有在当前目录下的文件  *find . * 会显示所有目">
<meta property="og:type" content="article">
<meta property="og:title" content="find指令">
<meta property="og:url" content="http://yoursite.com/2020/02/17/find%E6%8C%87%E4%BB%A4/index.html">
<meta property="og:site_name" content="tender healer">
<meta property="og:description" content="find指令在目录结构中搜索文件，并执行指定的操作。 1.命令格式find 路径 选项[-print -exec -ok..] 2.命令功能用于文件树中查找文件，并做出相应的处理 3.命令参数路径（pathname) : find命令查找的目录路径，用 . 表示当前目录，用 &#x2F; 表示系统目录  find . text.c  用此指令时会出现所有在当前目录下的文件  *find . * 会显示所有目">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://yoursite.com/2020/02/17/find%E6%8C%87%E4%BB%A4/1581909605074.png">
<meta property="og:image" content="http://yoursite.com/2020/02/17/find%E6%8C%87%E4%BB%A4/1581909659186.png">
<meta property="og:image" content="http://yoursite.com/2020/02/17/find%E6%8C%87%E4%BB%A4/1581910254991.png">
<meta property="og:image" content="http://yoursite.com/2020/02/17/find%E6%8C%87%E4%BB%A4/Center.png">
<meta property="og:image" content="http://yoursite.com/2020/02/17/find%E6%8C%87%E4%BB%A4/Center1.png">
<meta property="og:image" content="http://yoursite.com/2020/02/17/find%E6%8C%87%E4%BB%A4/Center2.jpg">
<meta property="og:image" content="http://yoursite.com/2020/02/17/find%E6%8C%87%E4%BB%A4/Center3.jpg">
<meta property="og:image" content="http://yoursite.com/2020/02/17/find%E6%8C%87%E4%BB%A4/Center4.jpg">
<meta property="og:image" content="http://yoursite.com/2020/02/17/find%E6%8C%87%E4%BB%A4/Center5.jpg">
<meta property="og:image" content="http://yoursite.com/2020/02/17/find%E6%8C%87%E4%BB%A4/Center6.jpg">
<meta property="og:image" content="http://yoursite.com/2020/02/17/find%E6%8C%87%E4%BB%A4/Center7.jpg">
<meta property="og:image" content="http://yoursite.com/2020/02/17/find%E6%8C%87%E4%BB%A4/Center8.jpg">
<meta property="og:image" content="http://yoursite.com/2020/02/17/find%E6%8C%87%E4%BB%A4/Center9.jpg">
<meta property="og:image" content="http://yoursite.com/2020/02/17/find%E6%8C%87%E4%BB%A4/Center10.png">
<meta property="article:published_time" content="2020-02-17T02:35:00.000Z">
<meta property="article:modified_time" content="2020-02-17T11:49:36.606Z">
<meta property="article:author" content="YQ Cong">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://yoursite.com/2020/02/17/find%E6%8C%87%E4%BB%A4/1581909605074.png">

<link rel="canonical" href="http://yoursite.com/2020/02/17/find%E6%8C%87%E4%BB%A4/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true
  };
</script>

  <title>find指令 | tender healer</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">tender healer</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <p class="site-subtitle">Recording learning gains</p>
  </div>

  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
  </ul>

</nav>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/02/17/find%E6%8C%87%E4%BB%A4/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="YQ Cong">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="tender healer">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          find指令
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2020-02-17 10:35:00 / 修改时间：19:49:36" itemprop="dateCreated datePublished" datetime="2020-02-17T10:35:00+08:00">2020-02-17</time>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="find指令"><a href="#find指令" class="headerlink" title="find指令"></a>find指令</h1><p>在目录结构中搜索文件，并执行指定的操作。</p>
<h2 id="1-命令格式"><a href="#1-命令格式" class="headerlink" title="1.命令格式"></a>1.命令格式</h2><p>find 路径 选项[-print -exec -ok..]</p>
<h2 id="2-命令功能"><a href="#2-命令功能" class="headerlink" title="2.命令功能"></a>2.命令功能</h2><p>用于文件树中查找文件，并做出相应的处理</p>
<h2 id="3-命令参数"><a href="#3-命令参数" class="headerlink" title="3.命令参数"></a>3.命令参数</h2><p>路径（pathname) : <strong>find命令查找的目录路径，用 . 表示当前目录，用 / 表示系统目录</strong></p>
<ul>
<li><p><strong>find . text.c</strong>  用此指令时会出现所有在当前目录下的文件</p>
</li>
<li><p>*<em>find . *</em> 会显示所有目录</p>
</li>
<li><p>*<em>find / 目录名 *</em> 会在系统目录下查找，<br>如：find / var 会显示在系统目录下所有关于var的文件</p>
</li>
<li><p><strong>-exec</strong> : find命令对匹配的文件执行该参数所给出的shell命令，相应的命令格式为*<em>‘命令’{} ;  *</em>   (注意{}和\之间的空格)<br>例：find code -exec ls {} ;</p>
<p><img src="/2020/02/17/find%E6%8C%87%E4%BB%A4/1581909605074.png" alt="img"></p>
</li>
<li><p><strong>-ok</strong>：和exec 作用相同，不过是一种更安全的模式来让执行该参数所给出的shell命令，每次执行前都会让用户来确定是否执行</p>
<h2 id="4-命令选项"><a href="#4-命令选项" class="headerlink" title="4.命令选项"></a>4.命令选项</h2></li>
<li><p><strong>-name</strong> ：按照文件名查找文件<br>例：find . -name code</p>
</li>
<li><p><strong>-perm</strong> : 按照文件权限来查找文件<br>例：find -perm -777 -print<br><strong>777</strong>是权限二进制的表示形式表示可读(r/4)可写(w/2)可执行(x/1)</p>
</li>
<li><p><strong>-prnue</strong>：表示不在当前指定的目录下查找<br>如果同时使用-depth选项，那么-prnue指令将被忽略<br>例：find -depth -prune</p>
<p><img src="/2020/02/17/find%E6%8C%87%E4%BB%A4/1581909659186.png" alt="img"></p>
</li>
<li><p><strong>-user 文件属主名</strong> ：按照文件属主来查找文件</p>
</li>
<li><p><strong>-group 文件所属组名</strong>：按照文件所属组来查找</p>
</li>
<li><p><strong>-mtime -n **或</strong>-mtime<strong>：按照文件更改时间来确认<br>**-n</strong>表示现在距更改文件几天以内，<strong>+n</strong>表示更改文件距离现在几天以前</p>
<p><img src="/2020/02/17/find%E6%8C%87%E4%BB%A4/1581910254991.png" alt="img"></p>
</li>
<li><p><strong>-nogroup</strong>：查无有效属组的文件，即文件的属组在 etc/groups中不存在</p>
</li>
<li><p><strong>-nouser</strong>：查无有效属主的文件，即文件的属主在/etc/passwd中不存在</p>
</li>
<li><p><strong>-newer file1 ! file2</strong> 查找更改时间比文件file1新但比文件file2旧的文件。</p>
</li>
<li><p><strong>-type</strong>查找某一类型的文件<br>类型：+ <strong>b</strong> 块设备<br> <strong>d</strong> 目录<br> <strong>c</strong> 字符设备文件<br> <strong>p</strong> 管道文件<br> <strong>l</strong> 符号链接文件<br> <strong>f</strong> 普通文件<br>如:查找块设备</p>
</li>
</ul>
<p><img src="/2020/02/17/find%E6%8C%87%E4%BB%A4/Center.png" alt="img"></p>
<ul>
<li><p><strong>-size n[c]</strong>表示查找文件长度为n快，带有c表示文件按字节计算</p>
<p><img src="/2020/02/17/find%E6%8C%87%E4%BB%A4/Center1.png" alt="img"><br>+<strong>-depth</strong>表示在当前目录找然后再在其子目录中找</p>
<p>例：find -depth</p>
</li>
<li><p><strong>-fstype</strong>：查找位于某⼀一类型⽂文件系统中的⽂文件，这些⽂文件系统类型通常可以在配置⽂文件/etc/fstab中找到</p>
</li>
<li><p><strong>-flowe</strong> 如果find命令遇到符号链接文件就跟踪至链接所指向的文件</p>
</li>
<li><p><strong>-cpio</strong> 将所匹配的文件备份到磁盘中</p>
<h2 id="5-按时间查找文件"><a href="#5-按时间查找文件" class="headerlink" title="5.按时间查找文件"></a>5.按时间查找文件</h2></li>
<li><p>如我们想查找三天以前的文件：<br>find /home/username/filename/ -mtime +3 -exec ls -l { } ;    <img src="/2020/02/17/find%E6%8C%87%E4%BB%A4/Center2.jpg" alt="img"></p>
</li>
<li><p>查找三天以内的文件<br>find/home/username/filename/ -mtime -3 -exec ls -l { } ;</p>
 <img src="/2020/02/17/find%E6%8C%87%E4%BB%A4/Center3.jpg" alt="img" style="zoom:150%;">

</li>
</ul>
<h2 id="6-查找文件大小为xx的文件："><a href="#6-查找文件大小为xx的文件：" class="headerlink" title="6.查找文件大小为xx的文件："></a>6.查找文件大小为xx的文件：</h2><ul>
<li><p>如find -size -1000c查找一个小于1000个字节的文件；截取一小部分为例</p>
<p><img src="/2020/02/17/find%E6%8C%87%E4%BB%A4/Center4.jpg" alt="img"></p>
</li>
<li><p>find / -amin -5查找系统最后5分钟系统访问的文件，我们取一小部分来展示</p>
<p><img src="/2020/02/17/find%E6%8C%87%E4%BB%A4/Center5.jpg" alt="img"></p>
</li>
<li><p>find , -atime -5查找当前目录下最后5天的访问的文件</p>
<p><img src="/2020/02/17/find%E6%8C%87%E4%BB%A4/Center6.jpg" alt="img"></p>
</li>
</ul>
<h2 id="7-查找当前所有目录并排序"><a href="#7-查找当前所有目录并排序" class="headerlink" title="7.查找当前所有目录并排序"></a>7.查找当前所有目录并排序</h2><ul>
<li><p>ll -t表示查询当前文件并且按照降序排列</p>
<p><img src="/2020/02/17/find%E6%8C%87%E4%BB%A4/Center7.jpg" alt="img"></p>
</li>
<li><p>ll -t |tac表示查询当前文件并且按照升序排列</p>
<p><img src="/2020/02/17/find%E6%8C%87%E4%BB%A4/Center8.jpg" alt="img"></p>
</li>
</ul>
<h2 id="8-查找当前目录下所有权限为755的⽂文件，并设置成777"><a href="#8-查找当前目录下所有权限为755的⽂文件，并设置成777" class="headerlink" title="8.查找当前目录下所有权限为755的⽂文件，并设置成777"></a>8.查找当前目录下所有权限为755的⽂文件，并设置成777</h2><p>分两步：</p>
<ul>
<li><p>i):修改权限命令<br> chmod 777 文件名</p>
<ul>
<li>1.chmod 775 /home/usernume </li>
<li>2.umask -p 0200</li>
<li>3.chown XXXX YYYY (XXXX 为用户名 YYYY为文件名）</li>
</ul>
</li>
<li><p>ii)权限列表</p>
<ul>
<li>-rw——-   (600) 只有所有者才有读和写的权限</li>
<li>-rw-r–r–   (644) 只有所有者才有读和写的权限，组群和其他人只有读的权限</li>
<li>-rwx——   (700) 只有所有者才有读，写，执行的权限</li>
<li>-rwxr-xr-x   (755) 只有所有者才有读，写，执行的权限，组群和其他人只有读和执行的权限</li>
<li>-rwx–x–x   (711) 只有所有者才有读，写，执行的权限，组群和其他人只有执行的权限</li>
<li>-rw-rw-rw-   (666) 每个人都有读写的权限</li>
<li>-rwxrwxrwx   (777) 每个人都有读写和执行的权限</li>
</ul>
</li>
<li><p>iii)：查找当前目录下权限为775的所有文件</p>
<p> <img src="/2020/02/17/find%E6%8C%87%E4%BB%A4/Center9.jpg" alt="img"></p>
</li>
<li><p>iiii)：将code 的权限设置为777r然后再找到权限为777的文件</p>
<p> <img src="/2020/02/17/find%E6%8C%87%E4%BB%A4/Center10.png" alt="img"></p>
</li>
</ul>

    </div>

    
    
    

      <footer class="post-footer">

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/02/16/file%E6%8C%87%E4%BB%A4/" rel="prev" title="file指令">
      <i class="fa fa-chevron-left"></i> file指令
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/02/18/%E9%9A%90%E5%86%99%E6%9C%AF/" rel="next" title="隐写术">
      隐写术 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#find指令"><span class="nav-number">1.</span> <span class="nav-text">find指令</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-命令格式"><span class="nav-number">1.1.</span> <span class="nav-text">1.命令格式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-命令功能"><span class="nav-number">1.2.</span> <span class="nav-text">2.命令功能</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-命令参数"><span class="nav-number">1.3.</span> <span class="nav-text">3.命令参数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-命令选项"><span class="nav-number">1.4.</span> <span class="nav-text">4.命令选项</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-按时间查找文件"><span class="nav-number">1.5.</span> <span class="nav-text">5.按时间查找文件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-查找文件大小为xx的文件："><span class="nav-number">1.6.</span> <span class="nav-text">6.查找文件大小为xx的文件：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7-查找当前所有目录并排序"><span class="nav-number">1.7.</span> <span class="nav-text">7.查找当前所有目录并排序</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#8-查找当前目录下所有权限为755的⽂文件，并设置成777"><span class="nav-number">1.8.</span> <span class="nav-text">8.查找当前目录下所有权限为755的⽂文件，并设置成777</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">YQ Cong</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">13</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">YQ Cong</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v4.2.0
  </div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">主题 – <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> v7.7.1
  </div>

        








      </div>
    </footer>
  </div>

  
  
  <script color='0,0,255' opacity='0.5' zIndex='-1' count='99' src="/lib/canvas-nest/canvas-nest.min.js"></script>
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

</body>
</html>
